#include "VMRPlayerView.h"
#include "Atoms.h"
#include "VMRPlayer.h"
#include "DX.h"
#include "DXWindow.h"
#include "VMRPlayerScrollView.h"

VMRPlayerView::VMRPlayerView( const MRect& rect, VMRPlayer* player ) : View( rect ), _player( player )
{
	
}

VMRPlayerView::~VMRPlayerView( )
{
	
}

void VMRPlayerView::update()
{
	D3DXMATRIX mTransf;
	D3DXVECTOR2 scale, transl;

	MRect clientRect = window()->getClientRect();
	float kx = 2.0f / clientRect.width();
	float ky = 2.0f / clientRect.height();

	scale.x = ( rect().width() ) / clientRect.width();
	scale.y = ( rect().height() ) / clientRect.height();
	transl.x = ( rect().width() ) / 2.0f * kx - 1.0f + rect().x() * kx;
	transl.y = ( rect().height() ) / 2.0f * ky - 1.0f + rect().y() * ky;
	
	D3DXMatrixTransformation2D( &mTransf, 0, 0, &scale, 0, 0, &transl );
	
	DX::_()->device->SetTransform( D3DTS_WORLD, &mTransf );

	/*DX::_()->device->SetRenderState( D3DRS_ALPHABLENDENABLE, true );
	DX::_()->device->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
	DX::_()->device->SetRenderState( D3DRS_BLENDOP, D3DBLENDOP_ADD );
	DX::_()->device->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );
		 
	DX::_()->device->SetRenderState( D3DRS_TEXTUREFACTOR, _alpha << 24 );*/

	_player->draw();

	//DX::_()->device->SetRenderState( D3DRS_ALPHABLENDENABLE, false );

	//DX::_()->device->SetTransform( D3DTS_WORLD, D3DXMatrixIdentity( &mTransf ) );

	View::update();
}

//void VMRPlayerView::leftMouseDown( IEvent event )
//{
//	_player->stop();
//}
//
//void VMRPlayerView::mouseMove( IEvent event )
//{
//	if ( event.lPressed )
//	{
//		_rect.x -= event.prevPoint.x - event.point.x;
//		_rect.y -= event.prevPoint.y - event.point.y;
//	}
//}
//
//void VMRPlayerView::leftMouseUp( IEvent event )
//{
//	_player->play();
//}